Skip to content

Conversation

@gjbauer
Copy link

@gjbauer gjbauer commented Nov 17, 2025

Add riscv64gc-unknown-uefi target

This PR includes the bare minimum changes currently required to include a riscv64gc-unknown-uefi target into the Rust compiler source tree. A few minor changes totally a handful of lines were required outside of the target's target.rs to get the build process to complete successfully, but these should not impose any challenges to existing targets.

One edit was made to the -unknown-uefi.md supported targets Markdown file to mention the existence of a tier 3 target. Since this target will originate as a tier 3 target, it will not be included in rustup for installation. I am willing to make more changes to the Markdown document in order to document how to build, install, and use this new target. Thank you for your consideration of this pull request!!

@rustbot
Copy link
Collaborator

rustbot commented Nov 17, 2025

Some changes occurred in src/doc/rustc/src/platform-support

cc @Noratrieb

These commits modify compiler targets.
(See the Target Tier Policy.)

@rustbot rustbot added A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 17, 2025
@rustbot
Copy link
Collaborator

rustbot commented Nov 17, 2025

r? @chenyukang

rustbot has assigned @chenyukang.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot
Copy link
Collaborator

rustbot commented Nov 17, 2025

⚠️ Warning ⚠️

  • The following commits have merge commits (commits with multiple parents) in your changes. We have a no merge policy so these commits will need to be removed for this pull request to be merged.

    You can start a rebase with the following commands:

    $ # rebase
    $ git pull --rebase https://github.com/rust-lang/rust.git main
    $ git push --force-with-lease
    

@rustbot rustbot added has-merge-commits PR has merge commits, merge with caution. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Nov 17, 2025
@rust-log-analyzer
Copy link
Collaborator

The job tidy failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
     };
     let binary_format = sess.target.binary_format.to_object();
-    
+
     if sess.target.arch == Arch::RiscV64 && binary_format == BinaryFormat::Coff {
         // Return None to use the fallback mechanism in create_wrapper_file
         // Use this fallback specifically for RISC-V 64 UEFI
Diff in /checkout/compiler/rustc_codegen_llvm/src/back/write.rs:1191:
         // We need custom section flags, so emit module-level inline assembly.
         // The "n" flags is currently not supported on RISC-V
         let mut section_flags = "";
-        if cgcx.target_arch != "riscv64"
-        {
-         if cgcx.is_pe_coff { section_flags = "n" } else { section_flags = "e" };
+        if cgcx.target_arch != "riscv64" {
+            if cgcx.is_pe_coff {
+                section_flags = "n"
+            } else {
+                section_flags = "e"
+            };
         }
         let asm = create_section_with_flags_asm(".llvmbc", section_flags, bitcode);
         llvm::append_module_inline_asm(llmod, &asm);
Diff in /checkout/compiler/rustc_target/src/spec/targets/riscv64gc_unknown_uefi.rs:1:
-use crate::spec::{
- Arch, Target, TargetMetadata, base
-};
+use crate::spec::{Arch, Target, TargetMetadata, base};
 
 pub(crate) fn target() -> Target {
     // Get the base UEFI configuration
Diff in /checkout/compiler/rustc_target/src/spec/targets/riscv64gc_unknown_uefi.rs:7:
     let mut base = base::uefi_msvc::opts();
-    
+
     // Override with RISC-V specific settings
     base.cpu = "generic-rv64".into();
     base.features = "+m,+a,+f,+d,+c".into();
Diff in /checkout/compiler/rustc_target/src/spec/targets/riscv64gc_unknown_uefi.rs:25:
         pointer_width: 64,
         data_layout: "e-m:e-p:64:64-i64:64-i128:128-n32:64-S128".into(),
         arch: Arch::RiscV64,
-        
+
         options: base,
     }
 }

// Return None to use the fallback mechanism in create_wrapper_file
// Use this fallback specifically for RISC-V 64 UEFI
return None;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this necessary?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thread 'rustc' panicked at compiler/rustc_codegen_ssa/src/back/metadata.rs:560:19:
called Result::unwrap() on an Err value: Error("unimplemented architecture Riscv64 with sub-architecture None")
stack backtrace:
0: 0x7fd4e3bee9cb - std::backtrace::Backtrace::create::h652c7106100133e9
1: 0x7fd4e3bee915 - std::backtrace::Backtrace::force_capture::hcbb8a9548a20f2ec
2: 0x7fd4db55d948 - std[e20d0b87aa1ec278]::panicking::update_hook::<alloc[d35db71d034d3387]::boxed::Box<rustc_driver_impl[709b8e3ce94d842e]::install_ice_hook::{closure#1}>>::{closure#0}
3: 0x7fd4e3bef91f - std::panicking::panic_with_hook::hd57cd463d793ed79
4: 0x7fd4e3bef6ca - std::panicking::panic_handler::{{closure}}::hddd6216c3fddee3b
5: 0x7fd4e3be6fe9 - std::sys::backtrace::__rust_end_short_backtrace::h5e7a56f283378525
6: 0x7fd4e3bc31ad - __rustc[256c90bb7e548b45]::rust_begin_unwind
7: 0x7fd4e3c60910 - core::panicking::panic_fmt::hf19c198748ef6a95
8: 0x7fd4e3c5f256 - core::result::unwrap_failed::he81173b5792ad6b0
9: 0x7fd4e2648404 - rustc_codegen_ssa[7f529d302ba2af36]::back::metadata::create_wrapper_file
10: 0x7fd4e25b485c - rustc_codegen_ssa[7f529d302ba2af36]::back::link::link_rlib
11: 0x7fd4e25a2008 - rustc_codegen_ssa[7f529d302ba2af36]::back::link::link_binary
12: 0x7fd4dba1f459 - <rustc_codegen_llvm[525d04dfcb951d0f]::LlvmCodegenBackend as rustc_codegen_ssa[7f529d302ba2af36]::traits::backend::CodegenBackend>::link
13: 0x7fd4db8eca19 - <rustc_interface[f3537463438a3ee8]::queries::Linker>::link
14: 0x7fd4db5b2b43 - rustc_span[eee2686a21fb97e]::create_session_globals_then::<(), rustc_interface[f3537463438a3ee8]::util::run_in_thread_with_globals<rustc_interface[f3537463438a3ee8]::util::run_in_thread_pool_with_globals<rustc_interface[f3537463438a3ee8]::interface::run_compiler<(), rustc_driver_impl[709b8e3ce94d842e]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}::{closure#0}>
15: 0x7fd4db5aa5b9 - std[e20d0b87aa1ec278]::sys::backtrace::_rust_begin_short_backtrace::<rustc_interface[f3537463438a3ee8]::util::run_in_thread_with_globals<rustc_interface[f3537463438a3ee8]::util::run_in_thread_pool_with_globals<rustc_interface[f3537463438a3ee8]::interface::run_compiler<(), rustc_driver_impl[709b8e3ce94d842e]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
16: 0x7fd4db5ad49e - <<std[e20d0b87aa1ec278]::thread::Builder>::spawn_unchecked
<rustc_interface[f3537463438a3ee8]::util::run_in_thread_with_globals<rustc_interface[f3537463438a3ee8]::util::run_in_thread_pool_with_globals<rustc_interface[f3537463438a3ee8]::interface::run_compiler<(), rustc_driver_impl[709b8e3ce94d842e]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[5b293a957d0a6e5f]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
17: 0x7fd4e3be180f - std::sys::thread::unix::Thread::new::thread_start::hbaf586a9e50a98cd
18: 0x7fd4d664b9cb -
19: 0x7fd4d66cfa0c -
20: 0x0 -

rustc version: 1.93.0-dev
platform: x86_64-unknown-linux-gnu

@bjorn3
Copy link
Member

bjorn3 commented Nov 17, 2025

Is there a full coff specification for riscv nowadays or are relocations still not supported on riscv? If the latter then how would you even use this target in the first place?

@gjbauer
Copy link
Author

gjbauer commented Nov 18, 2025

LLVM currently has a 'riscv64-unknown-windowstarget and ariscv64-unknown-efi` target, however they are both incomplete and produce ELF object files as opposed to COFF binaries. This renders them essentially unlinkable in the final stage of compilation. This will require changes to LLVM including a COFF writer in the RISC-V backend. Since the ultimate goal is to target UEFI applications, we shouldfocus on statically linked files without any need for relocations or dynamic linking...I will leave my branch active in case if it gets implemented, in which case I will submit a new PR

@gjbauer gjbauer closed this Nov 18, 2025
@rustbot rustbot removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. has-merge-commits PR has merge commits, merge with caution. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants